package com.tanhua.app.controller;

import com.tanhua.app.controllerservice.SettingsService;
import com.tanhua.domain.db.Settings;
import com.tanhua.domain.vo.UserHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/users")
public class SettingsController {

    @Autowired
    private SettingsService settingsService;


    @GetMapping(name = "设置--查询问题和通知",value = "/settings")
    public ResponseEntity findSettings(){
        return settingsService.findSettings();
    }


    @PostMapping(name = "设置--新增/修改问题",value = "/questions")
    public ResponseEntity saveOrUpdateQuestions(@RequestBody Map<String,String> map){
        String content = map.get("content");
        return settingsService.saveOrUpdateQuestions(content);
    }


    @PostMapping(name = "设置--新增/修改通知",value = "/notifications/setting")
    public ResponseEntity saveOrUpdateTZ(@RequestBody Settings settings){
        return settingsService.saveOrUpdateTZ(settings);
    }

    @GetMapping(name = "黑名单分页查询",value = "/blacklist")
    public ResponseEntity findBlackList(Integer page,Integer pagesize){
        return settingsService.findBlackList(page,pagesize);
    }

    @DeleteMapping(name = "删除黑名单的用户",value = "/blacklist/{uid}")
    public ResponseEntity deleteBlackById(@PathVariable("uid") Integer blackId){
        return settingsService.deleteBlackById(blackId, UserHolder.getUser().getId());
    }





    @PostMapping(name = "发送短信验证码",value = "/phone/sendVerificationCode")
    public ResponseEntity sendVerificationCode(){
        return  settingsService.sendVerificationCode();
    }


    @PostMapping(name = "校验验证码",value = "/phone/checkVerificationCode")
    public ResponseEntity checkVerificationCode(@RequestBody Map<String,String> map){

        String verificationCode = map.get("verificationCode");
        return settingsService.checkVerificationCode(verificationCode);
    }


    @PostMapping(name = "存手机号",value = "/phone")
    public ResponseEntity phone(@RequestBody Map map){


        return settingsService.phone(map);
    }






}
